@ECHO OFF
CLS

SET LOCALHOST=%computername%
ECHO Enter a Windows account (as DOMAIN\login)
SET /P LOGIN=under which to run the Snapshot Agent:
SET /P PASSWORD=Enter the password for this Windows account:
CLS

SET WorkingFolder="%ProgramFiles%\Microsoft SQL Server\100\Samples\Replication\ReplData"

ECHO Attempting to create the 'ReplData' share that replication uses as 
ECHO the working directory.
ECHO.
mkdir %WorkingFolder%
net share ReplData=%WorkingFolder% /remark:"Replication working directory for the SalesOrders sample."

REM Call sqlcmd to configure the publication.
sqlcmd -iCreateAdvWorksSalesOrdersPublication.sql -b -vlogin="N'%LOGIN%'" -vpassword="N'%PASSWORD%'" -vprogramfiles="N'%ProgramFiles%'" -V10
ECHO.

if errorlevel 10 goto criticalerror
ECHO The publication was created successfully.

ECHO You must create a virtual directory to use Web synchronization. 
ECHO If you plan to use a separate Web server, you must run the Web 
ECHO Synchronization Wizard on that Web server. 
ECHO (A certificate that supports SSL must already be installed.)

:runvdir
ECHO.
ECHO Do you want to create a virtual directory named SalesOrders for 
set choice=
set /p choice="Web synchronization on %computername%? [y,n] "
ECHO. 
if not '%choice%'=='' set choice=%choice:~0,1%
if /I '%choice%'=='y' goto createvdir
if /I '%choice%'=='n' goto runwizard
goto runvdir

:createvdir
REM Get the realm value.
ECHO Provide the realm name used for Web synchronization authentication.
ECHO (Note: the realm name and the server certificate name must match.)
SET /P realmname=Realm name:
ECHO.

START /WAIT CreateWebSyncVDir.bat -vdir SalesOrders -vdirfolder %systemdrive%\Inetpub\wwwroot\SalesOrders_VDIR -scriptfilename  %systemdrive%\Inetpub\AdminScripts\adsutil.vbs -realmname %realmname%

if errorlevel 1 goto vdirerror
goto success

:vdirerror
ECHO An error occurred or the virtual directory may already exist.
ECHO.

:runwizard
ECHO Run the Web Synchronization Wizard to enable Web synchronization.
ECHO. 

:success
ECHO After you build the Sales Orders sample, change the settings 
ECHO in the application configuration file to specify the name of
ECHO the Publisher and Subscriber instances.
ECHO.
goto end

:criticalerror
ECHO The publication could not be created. 
ECHO.

:end
PAUSE